-module(init_mnesia).


-export([start/0]).

-include("xengine.hrl").


get_nodes()->
	[node()].

start()->
	case 	mnesia:create_schema(get_nodes()) of
		{error , Reason } ->
			{"create schema error" , Reason} ;
		ok ->
		case  mnesia:start() of
			 {error ,Reason } ->
				Reason ;
			ok ->
				 %%需要保存到硬盘的静态数据
				 {atomic, ok} = mnesia:create_table(container , [{attributes,record_info(fields,container)},{disc_copies , get_nodes()} ]),
				 {atomic, ok} =	mnesia:create_table(app , [{attributes,record_info(fields,app)},{disc_copies , get_nodes()}]),
			 {atomic, ok} = mnesia:create_table(instance , [{attributes,record_info(fields,instance)} , {type,bag} ,{disc_copies,get_nodes()}]),
				 %%内存数据库中的动态数据
				 {atomic, ok} = mnesia:create_table(instance_runtime , [{attributes,record_info(fields,instance_runtime)} ,  {ram_copies,get_nodes()}]),
				 {atomic, ok} = mnesia:create_table(container_runtime , [{attributes,record_info(fields,container_runtime)} ,  {ram_copies,get_nodes()}]),
				  {atomic, ok} = mnesia:create_table(app_scable_log , [{attributes,record_info(fields,app_scable_log)} ,  {ram_copies,get_nodes()}]),
				  ok
		 end 
	end.



